<template>
  <base-breadcrumb :title="$route.meta.title">
    <searchData :search-data="searchOption" @search="search" />
    <a-card :bordered="false">
      <!-- <title-name title="策划执行书考核月度汇总"></title-name> -->
        <!-- :scroll="{ x: 1200 }" -->
      <list-table
        :defaultLoad="false"
        ref="table"
        :page-keys="['pageNum', 'pageSize','total']"
        size="default"
        rowKey="id"
        :columns="columns"
        :request="loadData"
        show-pagination="auto"
      >
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>

        <template slot="examineMonth" slot-scope="text, record, index">
          <span>{{text}}</span>
          <span v-if="record.isOutTime" style="color: #ff0000">（超时自动提交）</span>
        </template>

        <template slot="state" slot-scope="text, record, index">
          <span :style="text == '3' ? { color: '#ff0000' } : {}">{{stateName(text)}}</span>
        </template>

        <template slot="action" slot-scope="text, record">
          <MoreButton>
          <!-- 自查按钮 -->
          <template v-if="activeKey == '0'">
            <span v-if="record.state!=='3'" v-btnPermission="'pm_055_loo_01'">
              <a @click="handleOperation('look', record)">查看</a>
            </span>

            <span v-if="record.state === '0' || record.state === '4'" v-btnPermission="'pm_055_edi_02'">
              <a @click="handleOperation('edit', record)">编辑</a>
            </span>

            <template v-if="record.state == '2' || record.state == '4' || record.state == '5'">
              <approval-button :id="record.id" text="审批信息" />
            </template>

            <!-- 临时按钮 -->
            <!-- <span v-if="record.state == '1'">
              <a-divider type="vertical" />
              <a v-if="record.problem == '1'" @click="handleOperation('handelEffect', record)">处理</a>
            </span> -->
            <!-- 临时按钮 -->

            <span v-if="record.state === '5'" v-btnPermission="'pm_055_exp_03'">
              <!-- 审核通过的可导出 -->
              <ExportMould
                :servicei-url="exportConfig.server"
                :url="exportConfig.url"
                :is-button="false"
                :request-params="{id: record.id}"
              />
            </span>
          </template>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>

import { statusList2, searchOption, columns, testData } from './model.js'
import { getPagePlanExamineMonth, deletePlanExamine, getPlanExamineMonthExcel } from '@/api/project/projectPlanningAssessment'
import ExportMould from '@/components/ServiceExportMould'
export default {
  name: 'ProjectRecord',
  components: {
    ExportMould
  },
  data() {
    return {
      statusList2,
      searchOption,
      columns,
      activeKey: '0',

      exportConfig: getPlanExamineMonthExcel(),

      queryParam: {},
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, { param: this.queryParam })

        // return new Promise((resove, reject) => {
        //   resove({
        //     code: 200,
        //     data: testData,
        //     pageNum: 1,
        //     pageSize: 10,
        //     total: 6
        //   })
        // })
        return getPagePlanExamineMonth(requestParameters).then((res) => {
          console.log(res)
          return {code: 200, data: res.data.list, ...res.data }
        }).catch((err) => {
          return {
            code: 500,
            err
          }
        })
      },
    }
  },
  computed: {
    stateName() {
      return (val) => {
        return this.statusList2.find((v) => v.value == val)?.label
      }
    },
    currentPost() {
      return this.$currentPost()
    },
  },
  created() {
      // console.log('main created')
    // console.log(columns)
  },
  methods: {
    search(e) {
      let param = this.$clone(e)
      // if (param.examineYearMonthStart && param.examineYearMonthEnd) {
      //   param.examineYearMonthStart = param.examineYearMonthStart.replace('-', '')
      //   param.examineYearMonthEnd = param.examineYearMonthEnd.replace('-', '')
      // }
      if (param.grade) {
        param.gradeStart = param.grade.split(',')[0] * 1
        param.gradeEnd = param.grade.split(',')[1] * 1
        delete param.grade
      }
      this.queryParam = {
        ...param
      }
      this.$refs.table.refresh(true)
    },
    handleOperation(type, record = {}) {
      let { id } = record;
      this.$router.push({
        path: '/project/projectPlanningAssessment/monthlySummary/edit',
        query: {
          type,
          id,
        }
      })
    },
  }
}
</script>

<style>
</style>
